package com.ruoyi.group.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.group.domain.Communication;
import com.ruoyi.group.service.CommunicationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: CHL  <br/>
 * @ToDo: 工单沟通
 * Date: 2022/3/9:12:55  <br/>
 * Description:
 */
@Api(value = "/Communication",description = "工单沟通对应，传入工单id，可查询对应的交流记录，其他功能也可")
@RestController
@RequestMapping("/Communication")
public class CommunicationController extends BaseController {
    @Autowired
    CommunicationService communicationService;
    /**
     * Description : TODO  根据工单id查询沟通记录
     * ChangeLog : 1. 创建 (2022/3/9 13:20 [CHL]);
     * *
     * *  @return com.ruoyi.common.core.domain.AjaxResult
    **/
    @ApiOperation(value = "find/{roid}",httpMethod = "GET",response = AjaxResult.class)
    @GetMapping("find/{roid}")
    public AjaxResult getInfo(@PathVariable("roid")int roid){
        startPage();
        List<Communication> comm = communicationService.findComm(roid);
        return AjaxResult.success(comm);
    }
    @ApiOperation(value = "/addComm",httpMethod = "POST",response = AjaxResult.class)
    @PostMapping ("/addComm")
    public AjaxResult addComm(@RequestBody Communication communication){

        return toAjax(communicationService.addComm(communication));
    }
    @ApiOperation(value = "/delCommById",httpMethod = "GET",response = AjaxResult.class)
    //为什么会报该依赖没有GET这个枚举常量？
    @RequestMapping ("/delCommById")
    public AjaxResult delCommById(){
        //需要进行格式转换
        //传入前端queryParams里面的字段名，也就是沟通记录的id即可删除
        int commId = ServletUtils.getParameterToInt("CommId");
        return toAjax(communicationService.delCommById(commId));
    }

}
